import { BaseSkill } from '../BaseSkill';
import { DamageType, SkillType } from '../../types';
import { General } from '../../models/General';
import { Battle } from '../../models/Battle';

export class BaGuaZhen extends BaseSkill {
  private comboCount: number = 0;
  private readonly EXTRA_DAMAGE_RATIO = 0.5;

  constructor() {
    super(
      'baGuaZhen',
      '八卦阵',
      SkillType.Passive,
      DamageType.Strategy,
      0.5,  // 50% 触发概率
      3,    // 3回合CD
      2     // 2回合持续
    );
  }

  execute(source: General, battle: Battle): void {
    if (!this.canUse() || Math.random() > this.probability) return;

    if (Math.random() < 0.5 && this.comboCount < 3) {
      this.comboCount++;
      const extraDamage = source.attributes.intelligence * this.EXTRA_DAMAGE_RATIO;
      
      const target = battle.selectTarget(source);
      if (target) {
        target.receiveDamage(extraDamage);
      }
    } else {
      this.comboCount = 0;
    }

    if (this.comboCount === 0) {
      this.startCooldown();
    }
  }
}
